// pages/my_zong/my_zong.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked: false,
    array: ['微信', '线下'],
    index: "",
    ifxian: false,
    did:"",
    zid:"",
    money:"",
    money_index:0,
    tx_type:"0",
    tx_name:"微信"
  },
  money_chose:function(e){
    console.log(e)
    var index=e.currentTarget.dataset.index;
    var money=parseFloat(e.currentTarget.dataset.money);
    var moneys = parseFloat(this.data.list.money);
   
    if(moneys < money)
    {
      wx.showModal({
        title: '提示',
        content:"余额不足",

      })
    }else{
      this.setData({
        money_index:index,
        money:money
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var y_id = options.y_id
    that.setData({
      y_id:y_id
    })
    that.getDetail();
    that.getList();
    that.getJiesuan();
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  getDetail:function(){
    var that = this;
    var y_id = that.data.y_id;
    app.util.request({
      'url':"entry/wxapp/yaoshi.index",
      data:{
        openid:wx.getStorageSync('openid')
      },
      success:function(res){
        that.setData({
          list:res.data
        })
      }
    })
  },
  getList:function(){
    var that = this;
   
    app.util.request({
      'url':"entry/wxapp/yaoshi.tixian_list",
      
      success:function(res){
        that.setData({
          tixian_list:res.data
        })
      }
    })
  },
  getJiesuan:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/green.cash_base",
      success:function(res){
        that.setData({
          set:res.data,
          money:res.data.money[0]
        })
      }
    })
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var that = this
    var ifxian = that.data.ifxian
    if (e.detail.value == '1') {
      that.setData({
        ifxian: true,
      })
    } else {
      that.setData({
        ifxian: false,
      })
    }
    that.setData({
      index: e.detail.value
    })
  },
  //明细
  mingClick: function() {
    var y_id = this.data.y_id;
    wx.navigateTo({
      url: '/hyb_yl/yaoshi/pages/usermx/usermx?y_id=' + y_id,
    })
  },
  //须知
  xuzhi: function() {
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/xuzhi/xuzhi',
    })
  },
  //设置最大提现金额
  money: function(e) {
    var that = this
    var money = that.data.list.money
    //console.log(e)
    if (e.detail.value >= money) {
      var value = money
      that.setData({
        money: value
      })
    }else{
      that.setData({
        money:e.detail.value
      })
    }
  },
  choosetype:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var name = e.currentTarget.dataset.name;
    that.setData({
      tx_type:index,
      tx_name:name
    })
  },
  //提交
  subClick: function(e) {
    var that = this;
    var money = parseFloat(that.data.money);
    var moneys = parseFloat(that.data.list.money);
    console.log(moneys);
    console.log(money);
    var yid = that.data.y_id;
    var tx_type = that.data.tx_type;
    if(money == '')
    {
      wx.showToast({
        title: '请选择提现金额',
      })
    }else if(money > moneys){
      wx.showToast({
        title: '余额不足',
      })
    }else if(tx_type == ''){
      wx.showToast({
        title: '请选择提现方式',
      })
    }else {
      wx.showModal({
        title: '提示',
        content:'是否确认提现？',
        success:function(con)
        {
          if(con.confirm)
          {
            
            app.util.request({
              'url':"entry/wxapp/yaoshi.tixian",
              data:{
                openid:wx.getStorageSync('openid'),
                yid:yid,
                money:money,
                tx_type:tx_type
              },
              success:function(res){
                if(res.data.code == '1')
                {
                  wx.showModal({
                    title: '提示',
                    content:res.data.message
                  })
                }else{
                  wx.showModal({
                    title: '提示',
                    content:res.data.message,
                    success:function(con)
                    {
                      if(con.confirm)
                      {
                        wx.navigateBack({
                          complete: (res) => {},
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        }
      })
    }
    
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  
})